#ifndef _IME_H_
#define _IME_H_
#include <windows.h>
#include <interfacelib/ime/ime.h>

#define  IME_IN_COMPOSITION      0x01
#define  IME_IN_CHOSECAND        0x02

#pragma comment( lib , "IMM32.lib" )
namespace interfacelib
{
	namespace Window
	{
		class WindowDx;
		class Window;
	}
}

namespace interfacelib
{
	namespace IME
	{
		class IME
		{
		public:
#define	ENABLE_INPUT_HANGUL			1
#define	ENABLE_INPUT_ENGLISH		2
			IME();
			virtual ~IME();

			void initialize( interfacelib::Window::Window *window );

			bool checkIMEStatus();

			void startIMEContext();
			void finishIMEContext();

		private:	
			void getString( LPTSTR str );
			void getString( LPTSTR str , long flag );

			void onIMEStartComposition( WPARAM command, LPARAM data );
			void onIMEEndComposition( WPARAM command, LPARAM data );
			void onIMEComposition( WPARAM command, LPARAM data );
			void onIMECompositionFull( WPARAM command, LPARAM data );
			void onInputLangChange( WPARAM command, LPARAM data );
			void onIMESetContext( WPARAM command, LPARAM data );
			void onIMEControl( WPARAM command, LPARAM data );

			void setCompositionFont( LPLOGFONT logFont );
			void setCompositionWndPos( POINT& point );
			void getCompositionCursorPos();

		public:
			void onIMENotify( WPARAM command, LPARAM data );

			bool preTranslateMessage( UINT message, WPARAM wParam, LPARAM lParam );

			bool isHangulMode();
			void setHangulMode( bool isHangleMode );

			void setEnableInputEnglish( bool enableHangul );
			void setEnableInputHangul( bool enableEnglish );

			bool enableInputEnglish();
			bool enableInputHangul();

			void resetIME();

		private:
			int m_composedLength;
			int m_imeState;

			DWORD m_imeProperty;
			
			HWND m_windowHandle;
			HKL m_keyLayout;
			HIMC m_imc;

			BYTE m_inputLanguageMode;

			interfacelib::Window::Window *m_parentWindow;
		class Synchronized_IME
		{
		public:
			Synchronized_IME( IME *ime ) : m_ime( NULL )
			{
				m_ime = ime;
				m_ime->startIMEContext();
			};
			virtual ~Synchronized_IME()
			{
				m_ime->finishIMEContext();
			};

		private:
			IME *m_ime;
		};

		};
	}
}

#endif